class Task51:
    def run(self, array):
        buffer = [num for num in array]
        result = self.run_inner(array, buffer, 0, len(array))
        return result

    def run_inner(self, array, buffer, start, end):
        if end <= start + 1:
            return 0
        else:
            middle = (start + end) // 2
            result = self.run_inner(buffer, array, start, middle) + self.run_inner(buffer, array, middle, end)
            p1 = middle - 1
            p2 = end - 1
            p3 = end - 1
            while p1 >= start and p2 >= middle:
                if array[p1] > array[p2]:
                    buffer[p3] = array[p1]
                    result += (p2 - middle + 1)
                    p1 -= 1
                    p3 -= 1
                else:
                    buffer[p3] = array[p2]
                    p2 -= 1
                    p3 -= 1
            while p1 >= start:
                buffer[p3] = array[p1]
                p1 -= 1
                p3 -= 1
            while p2 >= middle:
                buffer[p3] = array[p2]
                p2 -= 1
                p3 -= 1
            return result
